package com.superm.service.impl;

import com.superm.entity.Emp;
import com.superm.entity.Supplier;
import com.superm.mappers.SupplierMapper;
import com.superm.service.SupplierService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SupplierServiceImpl implements SupplierService {

    @Autowired
    private SupplierMapper supplierMp;

    @Override
    public List<Supplier> selectLikeSupplierList(Supplier supplier, Integer pageNo, Integer pageSize) {
        System.out.println(supplier);
        return supplierMp.allSupplier(supplier,(pageNo-1)*pageSize,pageSize);
    }

    /**
     * 实现根据id查找供应商信息
     * @param supplierId
     * @return
     */
    @Override
    public Supplier selectIdSup(Integer supplierId) {
        return supplierMp.selectSupplierId(supplierId);
    }

    /**
     * 实现查询总条数
     * @param supplier
     * @return
     */
    @Override
    public int selectSupplierCount(Supplier supplier) {
        Supplier supplier1 = new Supplier();
        //将代替类的值获取过来
        BeanUtils.copyProperties(supplier,supplier1);
        return supplierMp.selectCount(supplier1);
    }

    /**
     * 实现修改供应商信息
     * @param supplier
     * @return
     */
    @Override
    public int updateSupplier(Supplier supplier) {
        Supplier supplier1 = new Supplier();
        //将代替类的值获取过来
        BeanUtils.copyProperties(supplier,supplier1);
        return supplierMp.updateInfoSupplier(supplier1);
    }

    /**
     * 实现添加供应商信息
     * @param supplier
     * @return
     */
    @Override
    public int addSupplier(Supplier supplier) {
        Supplier supplier1 = new Supplier();
        //将代替类的值获取过来
        BeanUtils.copyProperties(supplier,supplier1);
        return supplierMp.addInfoSupplier(supplier1);
    }

    /**
     * 实现删除供应商信息
     * @param supplierId
     * @return
     */
    @Override
    public int deleteSupplier(Integer supplierId) {
        return supplierMp.deleteInfoSupplier(supplierId);
    }

    @Override
    public List<Supplier> allSup() {
        return supplierMp.allSup();
    }
}
